package fr.cephb.joperon.structures;

import java.io.Serializable;

import fr.cephb.joperon.core.types.Fid;
import fr.cephb.util.JSONBuilder;
import fr.cephb.util.JSONizable;

public class SnpMap
implements Serializable,JSONizable
	{
	private static final long serialVersionUID = 1L;
	
    /* categories coded by getCat() */
    public static enum CATEGORY
            {
            UNK,
            SNP,DEL,INS,TRI,REP,MNP
            };

    /* categories coded by getCat() \
     *  ATTENTION PROBLEME A FIXER !!
     *
     * */
    public static enum ORIENTATION
            {
            Reverse,
            Forward,
            UNK
            };

	
	/**
     * p
     * Reference sequence 5' bp position.
     * it is stored as a int64_t
     */
     private long p;
            /**
     * q
     * Reference sequence 3' bp position.
     * it is stored as a int64_t
     */
     private long q;
            /**
     * x
     * Contig 5' bp position.
     * it is stored as a int64_t
     */
     private long x;
            /**
     * y
     * Contig 3' bp position.
     * it is stored as a int64_t
     */
     private long y;
            /**
     * cv
     * Confidence value.
     * it is stored as a int16_t
     */
     private short cv;
            /**
     * mw
     * NCBI dbSNP map weight.
     * it is stored as a int16_t
     */
     private short mw;
            /**
     * sc
     * Enum: NG, OK.
     * it is stored as a int16_t
     */
     private short sc;
            /**
     * ori
     * Orientation of SNP to reference sequence.
     * it is stored as a int16_t
     */
     private short ori;
            /**
     * cat
     * Enum: UNK, SNP, DEL, INS, TRI, REP, MNP.
     * it is stored as a int16_t
     */
     private short cat;
            /**
     * ver
     * NCBI dbSNP version when record was first submitted.
     * it is stored as a int16_t
     */
     private short ver;
            /**
     * fid
     * Feature map ID (15-digit string).
     * it is stored as a char*
     */
     private Fid fid = null;
            /**
     * ctg
     * Accession number of super contig.
     * it is stored as a char*
     */
     private String ctg = null;
            /**
     * acn
     * Accession number of SNP.
     * it is stored as a char*
     */
     private String acn = null;
            /**
     * band
     * Cytogenetic map location.
     * it is stored as a char*
     */
     private String band = null;
            /**
     * chr
     * CV term of organelle's short name.
     * it is stored as a char*
     */
     private String chr = null;
            /**
     * ca
     * Allele in reference sequence (contig allele).
     * it is stored as a char*
     */
     private String ca = null;
            /**
     * ra
     * Allele in reference SNP sequence (reference allele).
     * it is stored as a char*
     */
     private String ra = null;
            /**
     * aa
     * Allele in variant SNP sequence (alternative allele).
     * it is stored as a char*
     */
     private String aa = null;
            /**
     * flags
     * Single-character coded flags.
     * it is stored as a char*
     */
     private String flags = null;
     /**
      * getter for p
      * Reference sequence 5' bp position.
      * @return the value of p
      */
     public long getP()
             {
             return this.p;
             }
     /**
  * setter for p
  * Reference sequence 5' bp position.
  * @param  p the new value of p
  */
     public void setP(long p)
             {
             this.p=p;
             }
             /**
      * getter for q
      * Reference sequence 3' bp position.
      * @return the value of q
      */
     public long getQ()
             {
             return this.q;
             }
     /**
  * setter for q
  * Reference sequence 3' bp position.
  * @param  q the new value of q
  */
     public void setQ(long q)
             {
             this.q=q;
             }
             /**
      * getter for x
      * Contig 5' bp position.
      * @return the value of x
      */
     public long getX()
             {
             return this.x;
             }
     /**
  * setter for x
  * Contig 5' bp position.
  * @param  x the new value of x
  */
     public void setX(long x)
             {
             this.x=x;
             }
             /**
      * getter for y
      * Contig 3' bp position.
      * @return the value of y
      */
     public long getY()
             {
             return this.y;
             }
     /**
  * setter for y
  * Contig 3' bp position.
  * @param  y the new value of y
  */
     public void setY(long y)
             {
             this.y=y;
             }
             /**
      * getter for cv
      * Confidence value.
      * @return the value of cv
      */
     public short getCv()
             {
             return this.cv;
             }
     /**
  * setter for cv
  * Confidence value.
  * @param  cv the new value of cv
  */
     public void setCv(short cv)
             {
             this.cv=cv;
             }
             /**
      * getter for mw
      * NCBI dbSNP map weight.
      * @return the value of mw
      */
     public short getMw()
             {
             return this.mw;
             }
     /**
  * setter for mw
  * NCBI dbSNP map weight.
  * @param  mw the new value of mw
  */
     public void setMw(short mw)
             {
             this.mw=mw;
             }
             /**
      * getter for sc
      * Enum: NG, OK.
      * @return the value of sc
      */
     public short getSc()
             {
             return this.sc;
             }
     /**
  * setter for sc
  * Enum: NG, OK.
  * @param  sc the new value of sc
  */
     public void setSc(short sc)
             {
             this.sc=sc;
             }
             /**
      * getter for ori
      * Orientation of SNP to reference sequence.
      * @return the value of ori
      */
     public short getOri()
             {
             return this.ori;
             }
     /**
  * setter for ori
  * Orientation of SNP to reference sequence.
  * @param  ori the new value of ori
  */
     public void setOri(short ori)
             {
             this.ori=ori;
             }
             /**
      * getter for cat
      * Enum: UNK, SNP, DEL, INS, TRI, REP, MNP.
      * @return the value of cat
      */
     public short getCat()
             {
             return this.cat;
             }
     /**
  * setter for cat
  * Enum: UNK, SNP, DEL, INS, TRI, REP, MNP.
  * @param  cat the new value of cat
  */
     public void setCat(short cat)
             {
             this.cat=cat;
             }
             /**
      * getter for ver
      * NCBI dbSNP version when record was first submitted.
      * @return the value of ver
      */
     public short getVer()
             {
             return this.ver;
             }
     /**
  * setter for ver
  * NCBI dbSNP version when record was first submitted.
  * @param  ver the new value of ver
  */
     public void setVer(short ver)
             {
             this.ver=ver;
             }
             /**
      * getter for fid
      * Feature map ID (15-digit string).
      * @return the value of fid
      */
     public Fid getFid()
             {
             return this.fid;
             }
     /**
  * setter for fid
  * Feature map ID (15-digit string).
  * @param  fid the new value of fid
  */
     public void setFid(Fid fid)
             {
             this.fid=fid;
             }
             /**
      * getter for ctg
      * Accession number of super contig.
      * @return the value of ctg
      */
     public String getCtg()
             {
             return this.ctg;
             }
     /**
  * setter for ctg
  * Accession number of super contig.
  * @param  ctg the new value of ctg
  */
     public void setCtg(String ctg)
             {
             this.ctg=ctg;
             }
             /**
      * getter for acn
      * Accession number of SNP.
      * @return the value of acn
      */
     public String getAcn()
             {
             return this.acn;
             }
     /**
  * setter for acn
  * Accession number of SNP.
  * @param  acn the new value of acn
  */
     public void setAcn(String acn)
             {
             this.acn=acn;
             }
             /**
      * getter for band
      * Cytogenetic map location.
      * @return the value of band
      */
     public String getBand()
             {
             return this.band;
             }
     /**
  * setter for band
  * Cytogenetic map location.
  * @param  band the new value of band
  */
     public void setBand(String band)
             {
             this.band=band;
             }
             /**
      * getter for chr
      * CV term of organelle's short name.
      * @return the value of chr
      */
     public String getChr()
             {
             return this.chr;
             }
     /**
  * setter for chr
  * CV term of organelle's short name.
  * @param  chr the new value of chr
  */
     public void setChr(String chr)
             {
             this.chr=chr;
             }
             /**
      * getter for ca
      * Allele in reference sequence (contig allele).
      * @return the value of ca
      */
     public String getCa()
             {
             return this.ca;
             }
     /**
  * setter for ca
  * Allele in reference sequence (contig allele).
  * @param  ca the new value of ca
  */
     public void setCa(String ca)
             {
             this.ca=ca;
             }
             /**
      * getter for ra
      * Allele in reference SNP sequence (reference allele).
      * @return the value of ra
      */
     public String getRa()
             {
             return this.ra;
             }
     /**
  * setter for ra
  * Allele in reference SNP sequence (reference allele).
  * @param  ra the new value of ra
  */
     public void setRa(String ra)
             {
             this.ra=ra;
             }
             /**
      * getter for aa
      * Allele in variant SNP sequence (alternative allele).
      * @return the value of aa
      */
     public String getAa()
             {
             return this.aa;
             }
     /**
  * setter for aa
  * Allele in variant SNP sequence (alternative allele).
  * @param  aa the new value of aa
  */
     public void setAa(String aa)
             {
             this.aa=aa;
             }
             /**
      * getter for flags
      * Single-character coded flags.
      * @return the value of flags
      */
     public String getFlags()
             {
             return this.flags;
             }
     /**
  * setter for flags
  * Single-character coded flags.
  * @param  flags the new value of flags
  */
     public void setFlags(String flags)
         {
         this.flags=flags;
         }
     
     public CATEGORY getCategory()
         {
         if(getCat()<0 || getCat()>= CATEGORY.values().length) return CATEGORY.UNK;
         return CATEGORY.values()[getCat()];
         }


     public ORIENTATION getOrientation()
         {
         if(getOri()<0 || getOri()>= CATEGORY.values().length) return ORIENTATION.Reverse;
         return ORIENTATION.values()[getOri()];
         }

     
     
     @Override
	public int hashCode()
		{
		final int prime = 31;
		int result = 1;
		result = prime * result + ((acn == null) ? 0 : acn.hashCode());
		result = prime * result + ((fid == null) ? 0 : fid.hashCode());
		return result;
		}
     
    /** two SNPMap are equals if they have the same FID */ 
	@Override
	public boolean equals(Object obj)
		{
		if (this == obj) return true;
		if (obj == null) return false;
		if (getClass() != obj.getClass()) return false;
		SnpMap other = (SnpMap) obj;
		if (fid == null)
			{
			if (other.fid != null) return false;
			} else if (!fid.equals(other.fid)) return false;
		return true;
		}
	
	@Override
	public String toJSON()
    	 {
    	 JSONBuilder b= new JSONBuilder(); 
    	 b.put("p",getP());
    	 b.put("q",getQ());
    	 b.put("x",getX());
    	 b.put("y",getY());
    	 b.put("cv",getCv());
    	 b.put("mw",getMw());
    	 b.put("sc",getSc());
    	 b.put("ori",getOri());
    	 b.put("cat",getCat());
    	 b.put("ver",getVer());
    	 b.put("fid",getFid());
    	 b.put("ctg",getCtg());
    	 b.put("acn",getAcn());
    	 b.put("band",getBand());
    	 b.put("chr",getChr());
    	 b.put("ca",getCa());
    	 b.put("ra",getRa());
    	 b.put("aa",getAa());
    	 b.put("flags",getFlags());
    	 return b.toString();
    	 }
	@Override
	public String toString()
		{
		return toJSON();
		}
	}
